import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { IotDeviceGroupVO, IotDeviceGroupQuery, IotDeviceGroupForm } from './types'

/**
 * 查询设备分组列表
 */
export const listDeviceGroup = (query: IotDeviceGroupQuery): AxiosPromise<IotDeviceGroupVO[]> => {
  return request({
    url: '/iot/device-group/list',
    method: 'get',
    params: query
  })
}

/**
 * 分页查询设备分组列表
 */
export const pageDeviceGroup = (query: IotDeviceGroupQuery): AxiosPromise<any> => {
  return request({
    url: '/iot/device-group/page',
    method: 'get',
    params: query
  })
}

/**
 * 查询设备分组树形列表
 */
export const treeDeviceGroup = (): AxiosPromise<IotDeviceGroupVO[]> => {
  return request({
    url: '/iot/device-group/tree',
    method: 'get'
  })
}

/**
 * 查询设备分组详细
 */
export const getDeviceGroup = (groupId: number): AxiosPromise<IotDeviceGroupVO> => {
  return request({
    url: `/iot/device-group/${groupId}`,
    method: 'get'
  })
}

/**
 * 新增设备分组
 */
export const addDeviceGroup = (data: IotDeviceGroupForm) => {
  return request({
    url: '/iot/device-group',
    method: 'post',
    data: data
  })
}

/**
 * 修改设备分组
 */
export const updateDeviceGroup = (data: IotDeviceGroupForm) => {
  return request({
    url: '/iot/device-group',
    method: 'put',
    data: data
  })
}

/**
 * 删除设备分组
 */
export const delDeviceGroup = (groupIds: number | Array<number>) => {
  return request({
    url: `/iot/device-group/${groupIds}`,
    method: 'delete'
  })
} 